<?php 

$imgUrl = null;
define('BASE_URL', 'http://marketeronline.site11.com/index.php');
define('SIGN_UP_URL', BASE_URL.'?a=signup');

$name = 'acc_'.uniqid();
$email = 'acc_'.uniqid().'@yahoo.com';
$data = array(
    'a' => 'signup',
    'action' => 'signup',
    'fullname' => $name,
    'username' => $name,
    'password' => '123456',
    'password2' => '123456',
    'email' => $email,
    'email1' => $email,
    'sq' => uniqid(),
    'sa' => uniqid(),
	'agree' => 1,
    'validation_number' => '' 
);

if ($_POST){
	$imgUrl = getImage(SIGN_UP_URL);
	$data['validation_number'] = $_POST['validation_number']; 
	
	//url-ify the data for the POST
	$dataString = '';
	foreach($data as $key=>$value) { 
		$dataString .= $key.'='.$value.'&'; 
	}
	rtrim($dataString,'&');
	debug($dataString);
	
	//open connection
	$ch = curl_init();
	
	//set the url, number of POST vars, POST data
	curl_setopt($ch,CURLOPT_URL, SIGN_UP_URL);
	curl_setopt($ch,CURLOPT_POST, count($data));
	curl_setopt($ch,CURLOPT_POSTFIELDS, $dataString);
//	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	
	//execute post
	$result = curl_exec($ch);
	$info = curl_getinfo($ch);
	debug($info);
	
	//close connection
	curl_close($ch);
	
} else{
	$imgUrl = getImage(SIGN_UP_URL);
}

// Get captcha Image
function getImage(){
	$html_content_string = file_get_contents(SIGN_UP_URL);
	$xpath_string = '/html/body/form/table/tbody/tr[10]/td[1]/img';
	
	$img = preg_match('/(?<=\<img\ssrc\=\").*(?=">)/', $html_content_string, $m);
	if ($m){
		return BASE_URL.$m[0]; 
	}
	return false;
}

//write CSV
function _writeTsv($errorCode = 0){
	//set Japan time
	date_default_timezone_set('Asia/Tokyo');
	
	$tsvData = array(
		'access_time' => date('YmdHis'),
		'session_id' => $this->_sessionId,
		'mpv' => $this->_mpv,
		'link_url' => $this->_linkUrl,
		'user_agent' => $_SERVER['HTTP_USER_AGENT'],
		'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
		'remote_ip' => $this->getIp(),
		'status_code' => $errorCode
	);
//	debug($tsvData);
	
	//create a file
	$filename = 'click_'.date('YmdH').((int)(date('i')/10)).'0.tsv';
	$csv_file = fopen(TRACK_LOG_DIR.'tsv'. DS . $filename, 'a+');
	if (!$csv_file){
		//export log : Failed to write click_log
		$this->_exportLog('Failed to write click_log');
		return false;
	} else{
		//export log : Write click_log
		$this->_exportLog('Write click_log');
	}
 
	// The column headings of your .csv file
	$contents = fread($csv_file, 1024);
	if (!$contents){
		$header_row = array("access_time", "session_id", "mpv", "link_url", "user_agent", "referer", "remote_ip", "status_code");
		fputcsv($csv_file, $header_row, "\t", '"');
	}
	
	fputcsv($csv_file, $tsvData, "\t", "\"");
	fclose($csv_file);
}

// Debug
function debug($data){
	echo '<pre>';
	print_r($data);
	echo '</pre>';
}
?>

<iframe style="position: absolute; top: 30px; right: 30px" src="<?php echo SIGN_UP_URL;?>" width="500" height="500"></iframe>
<form method="post" action="" name="regform">
 	<img src="<?php echo $imgUrl;?>">
	<input type="text" name="validation_number" class="inpts" size="15">
	<input type="submit" value="Register" class="sbmt">
</form>